<template>
  <div id="aCoursesList" class="bg-fa of">
    <div class="mt40">
      <!-- /无数据提示 开始-->
      <section class="no-data-wrap" v-if="data.total == 0">
        <em class="icon30 no-data-ico">&nbsp;</em>
        <span class="c-666 fsize14 ml10 vam"
        >没有收藏课程...</span
        >
      </section>
      <!-- /无数据提示 结束-->
      <!-- 数据列表 开始-->
      <article v-if="data.total > 0" class="comm-course-list">
        <ul id="bna" class="of">
          <li v-for="item in data.items" :key="item.id">
            <div class="cc-l-wrap">
              <section class="course-img">
                <img
                  :src="item.cover"
                  class="img-responsive"
                  alt="课程封面"
                />
                <div class="cc-mask">
                  <a
                    :href="'/course/' + item.id"
                    title="开始学习"
                    class="comm-btn c-btn-1"
                  >开始学习</a
                  >
                </div>
              </section>
              <h3 class="hLh30 txtOf mt10">
                <a
                  :href="'/course/' + item.id"
                  :title="item.title"
                  class="course-title fsize18 c-333"
                >{{ item.title }}</a
                >
              </h3>
              <section class="mt10 hLh20 of">
                    <span
                      v-if="Number(item.price) !== 0"
                      class="fr jgTag bg-green"
                    >
                      <i class="c-fff fsize12 f-fA">{{ item.price }}元</i>
                    </span>
                <span
                  v-else
                  class="fr jgTag bg-green"
                >
                      <i class="c-fff fsize12 f-fA">免费</i>
                    </span>
              </section>
            </div>
          </li>
        </ul>
        <div class="clear" />
      </article>
      <!-- /数据列表 结束-->
    </div>
    <div>
      <div class="paging">
        <!-- undisable这个class是否存在，取决于数据属性hasPrevious -->
        <a
          :class="{ undisable: !data.hasPrevious }"
          href="#"
          title="首页"
          @click.prevent="gotoPage(1)"
        >&lt;&lt;</a
        >
        <a
          :class="{ undisable: !data.hasPrevious }"
          href="#"
          title="前一页"
          @click.prevent="gotoPage(data.current - 1)"
        >&lt;</a
        >
        <a
          v-for="page in data.pages"
          :key="page"
          :class="{
                current: data.current == page,
                undisable: data.current == page
              }"
          :title="'第' + page + '页'"
          href="#"
          @click.prevent="gotoPage(page)"
        >{{ page }}</a
        >
        <a
          :class="{ undisable: !data.hasNext }"
          href="#"
          title="后一页"
          @click.prevent="gotoPage(data.current + 1)"
        >&gt;</a
        >
        <a
          :class="{ undisable: !data.hasNext }"
          href="#"
          title="末页"
          @click.prevent="gotoPage(data.pages)"
        >&gt;&gt;</a
        >
        <div class="clear" />
      </div>
    </div>
  </div>
</template>
<script>
import courseApi from "@/api/course";
export default {
  data(){
    return {
      data: {}
    };
  },
  created() {
    this.initCollect();
  },
  methods: {
    initCollect(){
      courseApi.getPageCollect(1,8).then(response => {
        this.data = response.data.data;
      })
    },
    gotoPage(page){
      courseApi.getPageCollect(page,8).then(response => {
        this.data = response.data.data;
      })
    }
  }
};
</script>
